﻿using System;
using System.Collections.Generic;
using Framework.Message.SMS.SGIP.Commands;

namespace Framework.Message.SMS.SGIP
{
    public class CommandFactory
    {
        public static Command GetCommandFormByte(byte[] bytes)
        {
            SGIPCommandType commandType = (SGIPCommandType)ByteIntConvert.Bytes2UInt(bytes, 4);
            switch (commandType)
            {
                case SGIPCommandType.Ping:
                    return new PingCommand(bytes);
                case SGIPCommandType.Ping_Resp:
                    return new PingRespCommand(bytes);
                case SGIPCommandType.Bind:
                    return new BindCommand(bytes);
                case SGIPCommandType.Bind_Resp:
                    return new BindRespCommand(bytes);
                case SGIPCommandType.Unbind:
                    return new UnbindCommand(bytes);
                case SGIPCommandType.Unbind_Resp:
                    return new UnbindRespCommand(bytes);
                case SGIPCommandType.Submit:
                    return new SubmitCommand(bytes);
                case SGIPCommandType.Submit_Resp:
                    return new SubmitRespCommand(bytes);
                case SGIPCommandType.Deliver:
                    return new DeliverCommand(bytes);
                case SGIPCommandType.Deliver_Resp:
                    return new DeliverRespCommand(bytes);
                case SGIPCommandType.Report:
                    return new ReportCommand(bytes);
                case SGIPCommandType.Report_Resp:
                    return new ReportRespCommand(bytes);
                default:
                    return null;
            }
        }

        public static Command GetNewCommand(SGIPCommandType commandType, CommandSequence sequence)
        {
            switch (commandType)
            {
                case SGIPCommandType.Ping:
                    return new PingCommand(sequence);
                case SGIPCommandType.Ping_Resp:
                    return new PingRespCommand(sequence);
                case SGIPCommandType.Bind:
                    return new BindCommand(sequence);
                case SGIPCommandType.Bind_Resp:
                    return new BindRespCommand(sequence);
                case SGIPCommandType.Unbind:
                    return new UnbindCommand(sequence);
                case SGIPCommandType.Unbind_Resp:
                    return new UnbindRespCommand(sequence);
                case SGIPCommandType.Submit:
                    return new SubmitCommand(sequence);
                case SGIPCommandType.Submit_Resp:
                    return new SubmitRespCommand(sequence);
                case SGIPCommandType.Deliver:
                    return new DeliverCommand(sequence);
                case SGIPCommandType.Deliver_Resp:
                    return new DeliverRespCommand(sequence);
                case SGIPCommandType.Report:
                    return new ReportCommand(sequence);
                case SGIPCommandType.Report_Resp:
                    return new ReportRespCommand(sequence);
                default:
                    return null;
            }
        }

        public static CommandT GetNewCommand<CommandT>(CommandSequence sequence) where CommandT : Command, new()
        {
            CommandT command = new CommandT();
            command.Header = new CommandHeader(command.CommandType, command.BodyLength, sequence);
            return command;
        }

    }
}
